package com.examples.painting;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;

public class ResizingRedrawingWithFlicker {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		final String[] list = new String[128];
		for (int i = 0; i < list.length; i++) {
			list[i] = i + "-String-that-is-quite-long-" + i;
		}
		Display display = Display.getDefault();
		int style = SWT.SHELL_TRIM | SWT.NO_REDRAW_RESIZE;
		
		final Shell shell = new Shell(display, style);
		
		shell.addListener(SWT.Paint, new Listener() {
			public void handleEvent(Event event) {
				GC gc = event.gc;
				int height = gc.stringExtent("").y;
				for (int i = 0; i < list.length; i++) {
					gc.drawText(list[i], 2, i * height);
				}
			}
		});
		shell.setSize(200, 200);
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
	}
}